import 'package:flutter/material.dart';
import 'package:flutter1/demo/layout_page.dart';
import 'package:flutter_color_plugin/flutter_color_plugin.dart';

class StatefallGroupPage extends StatefulWidget {
  const StatefallGroupPage({super.key});

  @override
  State<StatefallGroupPage> createState() => _StatefallGroupPageState();
}

class _StatefallGroupPageState extends State<StatefallGroupPage> {
  var _currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: '_StatefallGroupPageState',
      theme: ThemeData(
        colorScheme:
            ColorScheme.fromSeed(seedColor: ColorUtil.color('#f2f2f2')),
        useMaterial3: true,
      ),
      home: Scaffold(
          appBar: AppBar(
            backgroundColor: Theme.of(context).colorScheme.inversePrimary,
            title: Text("title"),
            leading: GestureDetector(
              onTap: () {
                Navigator.pop(context);
              },
              child: Icon(Icons.arrow_back_sharp),
            ),
          ),
          bottomNavigationBar: BottomNavigationBar(
            currentIndex: _currentIndex,
            onTap: (index) {
              setState(() {
                _currentIndex = index;
              });
            },
            items: const [
              BottomNavigationBarItem(
                  icon: Icon(Icons.home, color: Colors.grey),
                  activeIcon: Icon(Icons.home, color: Colors.green),
                  label: "Home"),
              BottomNavigationBarItem(
                  icon: Icon(Icons.list, color: Colors.grey),
                  activeIcon: Icon(Icons.list, color: Colors.green),
                  label: "List"),
              BottomNavigationBarItem(
                  icon: Icon(Icons.settings, color: Colors.grey),
                  activeIcon: Icon(Icons.settings, color: Colors.green),
                  label: "Settings"),
            ],
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {},
            child: Text("点我"),
          ),
          body: RefreshIndicator(
              child: ListView(children: [getPage(_currentIndex)]),
              onRefresh: _handleRefresh)
          // This trailing comma makes auto-formatting nicer for build methods.
          ),
    );
  }

  Future _handleRefresh() async {
    await Future.delayed(Duration(seconds: 1));
  }

  getPage(int currentIndex) {
    if (currentIndex == 0) {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const TextField(
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.fromLTRB(5, 0, 0, 0),
                  hintText: '请输入',
                  hintStyle: TextStyle(color: Colors.grey)),
            ),
            Text(
              'You have pushed the button this many times:',
              style: TextStyle(
                color: ColorUtil.color('#aa88f2'),
              ),
            ),
            Text(
              '2222',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      );
    } else if (currentIndex == 1) {
      return Container(
        height: 500,
        margin: EdgeInsets.only(top: 10),
        decoration: BoxDecoration(color: Colors.lightBlueAccent),
        child: PageView(
          children: [
            Image.network(
                'https://znas.cn/share/transcode/share/file/thumb?nid=KEYDEMBQGAZDAUSHIRNDK&dtoken=VFUoQzLIVY3OLs2ED3knGCwlCMQLAlW1fQjWPrhsxM6yCZ24TINb50WzUWH42Hzf6cGpOVEo6cdjEndZH66DWtn2tNM0q5czfaIzq8XVZQPghYtzkJhZem3dvxnlSJ2p3tDVkaDm2QetMi3VnHrgTbSgm4m4&path=E.lepyBkZQnI8GitOLJyfu7f7X9ClkNuKY2eb31XAuElKm3BG40DM88j5TRnflm3pfSZYIMhRn6Zyc5EZCQbPlUigyCBksNDvMeA2NNxRs3YXYUNjFAXbqY271tp1eUVEnIM3m3upIJZzdqKQH7Ts0YjZ0gm4m4&dest_fmt=large&request_purpose=5&device_type=h5'),
            Image.network(
                'https://znas.cn/share/transcode/share/file/thumb?nid=KEYDEMBQGAZDAUSHIRNDK&dtoken=VFUoQzLIVY3OLs2ED3knGCwlCMQLAlW1fQjWPrhsxM6yCZ24TINb50WzUWH42Hzf6cGpOVEo6cdjEndZH66DWtn2tNM0q5czfaIzq8XVZQPghYtzkJhZem3dvxnlSJ2p3tDVkaDm2QetMi3VnHrgTbSgm4m4&path=E.lepyBkZQnI8GitOLJyfu7f7X9ClkNuKY2eb31XAuElKm3BG40DM88j5TRnflm3pfSZYIMhRn6Zyc5EZCQbPlUigyCBksNDvMeA2NNxRs3YXYUNjFAXbqY271tp1eUVEnIM3m3upIJZzdqKQH7Ts0YjZ0gm4m4&dest_fmt=large&request_purpose=5&device_type=h5'),
            Image.network(
                'https://znas.cn/share/transcode/share/file/thumb?nid=KEYDEMBQGAZDAUSHIRNDK&dtoken=VFUoQzLIVY3OLs2ED3knGCwlCMQLAlW1fQjWPrhsxM6yCZ24TINb50WzUWH42Hzf6cGpOVEo6cdjEndZH66DWtn2tNM0q5czfaIzq8XVZQPghYtzkJhZem3dvxnlSJ2p3tDVkaDm2QetMi3VnHrgTbSgm4m4&path=E.lepyBkZQnI8GitOLJyfu7f7X9ClkNuKY2eb31XAuElKm3BG40DM88j5TRnflm3pfSZYIMhRn6Zyc5EZCQbPlUigyCBksNDvMeA2NNxRs3YXYUNjFAXbqY271tp1eUVEnIM3m3upIJZzdqKQH7Ts0YjZ0gm4m4&dest_fmt=large&request_purpose=5&device_type=h5'),
          ],
        ),
      );
    } else if (currentIndex == 2) {
      return const LayoutPage();
    }
  }
}
